<?php
class My_Forms_Admin_Sorts extends Zend_Form {
	public function __construct($kid = null, $sname = null, $action = null, $url = null, $options = null) {
		parent::__construct ( $options );
		$this->setName ( 'msg' )->setAction ( $url );
		
		$name = new Zend_Form_Element_Text ( 'name' );
		$name->setLabel ( 'name:' )->setRequired ( true )->addValidator ( 'NotEmpty', true )->setValue ( $sname );
		
		$auth = Zend_Auth::getInstance ();
		if ($auth->getIdentity ()->group != 'admin') {
			$ke = new Zend_Form_Element_Hidden ( 'kid' );
		} else {
			$ke = new Zend_Form_Element_Select ( 'kid' );
			
			$keDb = new Keshi ( );
			$s = $keDb->select ();
			$s->from ( 'bc_keshi', array ('id', 'kename' ) );
			
			$keDb = $keDb->fetchAll ( $s )->toArray ();
			foreach ( $keDb as $v ) {
				$a [] = $v ['id'];
				$b [] = $v ['kename'];
			}
			$ke->setLabel ( 'keshi:' )->addMultiOptions ( array_combine ( $a, $b ) );
		}
		$ke->setValue ( $kid );
		
		$submit = new Zend_Form_Element_Submit ( 'submit' );
		$submit->setLabel ( $action );
		
		$this->addElements ( array ($name, $ke, $submit ) );
	}
}
?>